package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IWithdrawView
import de.baumann.browser.model.CenterModel
import de.baumann.browser.utils.getUser

@Deprecated("过期")
class WithdrawPresenter : BasePresenter<IWithdrawView>() {
    private val centerModel = CenterModel()

    fun getEthAndPhone() {
        val loginInfo = getUser()
        if (loginInfo == null || view == null) {
            return
        }
        view.setEthUrl(loginInfo.eth_address)
        view.setPhone(loginInfo.phone)
    }


    fun getSmsCode() {
        this.centerModel.withdrawGetSmsCode(view.amount, view.ethUrl, view.phone)
                .subscribe(object : OdinObserver<Any>(view) {
                    override fun onSuccess(data: Any?) {
                        if (view != null)
                            view.smsCodeSent()
                    }
                })
    }

    fun withdraw() {
        this.centerModel.withdraw(view.amount, view.smsCode)
                .subscribe(object : OdinObserver<Any>(view) {
                    override fun onSuccess(data: Any?) {
                        if (view != null)
                            view.withdrawSuccess()
                    }
                })
    }
}